package com.gemme.gemme.view;

import android.content.Context;
import android.media.Image;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.gemme.gemme.R;
import com.gemme.gemme.wode.WuliuBean;

import java.util.List;

public class WuliuView extends RelativeLayout {
    private Context context;
    public WuliuView(Context context) {
        this(context,null);
    }

    public WuliuView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public WuliuView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        initView();
    }
    RelativeLayout rl_content;
    LinearLayout ll_content;
    ImageView iv_picture;
    TextView tv_state;
    TextView tv_name;
    TextView tv_telephone;
    LinearLayout ll_wuliu;
    private void initView() {
        LayoutInflater.from(context).inflate(R.layout.wuliu_view,this);
        rl_content = findViewById(R.id.rl_content);
        ll_content = findViewById(R.id.ll_content);


        iv_picture = findViewById(R.id.iv_picture);
        tv_state = findViewById(R.id.tv_state);
        tv_name = findViewById(R.id.tv_name);
        tv_telephone = findViewById(R.id.tv_telephone);
        ll_wuliu = findViewById(R.id.ll_wuliu);


        rl_content.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
              if(  ll_content.getVisibility() == View.GONE){
                  ll_content.setVisibility(VISIBLE);
              }else{
                  ll_content.setVisibility(GONE);
              }
            }
        });
    }

/*
* iv_picture
tv_state
tv_name
tv_telephone
ll_wuliu
* */

    public void setData(WuliuBean wuliuBean) {
        if(wuliuBean == null)
            return;
        try {
            WuliuBean.ResultBean result = wuliuBean.getResult();
            List<WuliuBean.ResultBean.ListBean> list = result.getList();
            Glide.with(iv_picture).load(result.getLogo()).into(iv_picture);
//            tv_state.setText();
            tv_name.setText(result.getExpName() + ":" + result.getExpPhone());
            tv_telephone.setText( "客服电话:"+ result.getCourierPhone());

            for (int i = 0; i < list.size(); i++) {
                WuliuBean.ResultBean.ListBean bean = list.get(i);
                SingleWuliuView singleWuliuView = new SingleWuliuView(context);
                singleWuliuView.setData(bean);
                ll_wuliu.addView(singleWuliuView);

            }
        }catch (Exception e){

        }

    }
}
